
import { Settings } from "../../types";
import { Controller } from "../types";
import { SettingEvent } from "../../events";
import { open } from "./loaders/vim-loader/progressive/open.ts";

const { BASE_URL } = import.meta.env
export class SettingHandler extends Controller {
  urls = new Set<string>()


  handler = async ({ renderer, detail }: SettingEvent) => {
    // const os=this.urls.size
    // todo  需要前后对比url的差异
    // detail.models.urls.filter(v=>!this.urls.has(v))

    const url = detail.models.urls.at(0)
    /* const bfast = new BFast(BASE_URL + url)
    const geometryBfast = await bfast.getBfast('geometry')
    const g3dInfo = await G3d.createFromBfast(geometryBfast)
    const subset = new G3dSubset(g3dInfo).except('instance',) */
    open(BASE_URL + url, {})
      .then((vim) => {
        vim.loadMesh((obj3d) => {

          renderer.scene.add(obj3d)
        })

      })


  }
  constructor(setting: Settings) {
    super()
    setting.models.urls.forEach(url => {
      this.urls.add(url)
    })
  }

}